package com.ms.pda.messenger

import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.MutableLiveData
import com.blankj.utilcode.util.StringUtils
import com.ms.pda.R
import com.ms.pda.base.BaseViewModel
import com.ms.pda.model.vo.SubmitFailedVO
import java.util.stream.Collectors

class SubmitFailedMessenger : BaseViewModel() {

    val failedCollection: MutableLiveData<MutableList<SubmitFailedVO>> = MutableLiveData(
        mutableListOf()
    )

    /**
     * 扫码是否存在错误列表校验
     */
    fun checkCodeExist(code: String): Boolean {
        return failedCollection.value!!.stream().anyMatch {
            StringUtils.equals(it.code, code)
        }
    }

    /**
     * 绑定码失败删除
     */
    suspend fun deleteBindCode(activity: AppCompatActivity, code: String) {

        failedCollection.value =
            failedCollection.value!!.stream().filter { !StringUtils.equals(it.code, code) }
                .collect(Collectors.toList())
    }

    /**
     * 拆箱拆托失败删除
     */
    suspend fun deleteDismantleCode(activity: AppCompatActivity, code: String) {

        failedCollection.value =
            failedCollection.value!!.stream().filter { !StringUtils.equals(it.code, code) }
                .collect(Collectors.toList())
    }

    /**
     * 配套包装失败删除
     */
    suspend fun deleteMatchingCode(activity: AppCompatActivity, code: String) {

        failedCollection.value =
            failedCollection.value!!.stream().filter { !StringUtils.equals(it.code, code) }
                .collect(Collectors.toList())
    }

    /**
     * 二次包装失败删除
     */
    suspend fun deleteSecondaryCode(activity: AppCompatActivity, code: String) {

        failedCollection.value =
            failedCollection.value!!.stream().filter { !StringUtils.equals(it.code, code) }
                .collect(Collectors.toList())
    }

    /**
     * 出入库失败删除
     */
    suspend fun deleteStorageCode(activity: AppCompatActivity, code: String) {

        failedCollection.value =
            failedCollection.value!!.stream().filter { !StringUtils.equals(it.code, code) }
                .collect(Collectors.toList())
    }

    /**
     * 退货失败删除
     */
    suspend fun deleteReturnCode(activity: AppCompatActivity, code: String) {

        failedCollection.value =
            failedCollection.value!!.stream().filter { !StringUtils.equals(it.code, code) }
                .collect(Collectors.toList())
    }


}